<template>
  <div class="madp-choose-member-dialog" v-show="visible">
    <div class="dialog-bg"></div>
    <div class="com-dialog-container">
      <div class="header">
        <span class="title">选择客户</span>
        <i class="el-icon-close cursor-pointer" @click="closeDialog"></i>
      </div>
      <div class="container">
        <mescroll-view :showMoreBtn="page.current * page.size < page.total" @getMoreData="getMoreData">
          <div v-for="(item, idx) in list" :key="idx" class="list-item cursor-pointer" @click="chooseMember(item)">
            <img :src="item.avatar || $defaultAvatar" alt />
            <div class="info">
              <span>{{ item.name }}</span>
              <span>@{{ item.typeText }}</span>
            </div>
          </div>
        </mescroll-view>
      </div>
    </div>
  </div>
</template>
<script>
import MescrollView from '@/components/material/mescroll-view.vue'
import * as customerDetailApi from '@/api/customer-details'
export default {
  name: 'MemberListComponent',
  components: { MescrollView },
  data() {
    return {
      list: [],
      page: {
        current: 1,
        size: 10,
        total: 0
      }
    }
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    wxUserId: {
      type: String,
      default: ''
    },
    chatId: {
      type: String,
      default: ''
    }
  },
  created() {},
  mounted() {
    this.fetchCustomerList()
  },
  methods: {
    closeDialog() {
      this.$emit('update:visible', false)
    },
    chooseMember(info) {
      this.$emit('memberInfoFn', info)
    },
    getMoreData() {
      this.page.current++
      this.fetchCustomerList()
    },
    fetchCustomerList() {
      let params = {
        wxUserId: this.wxUserId,
        chatId: this.chatId || '',
        current: this.page.current,
        size: this.page.size
      }
      customerDetailApi.customerListByWxUserId(params).then((res) => {
        this.list = res.data.data.records
        this.page.total = res.data.data.total
      })
    }
  }
}
</script>
<style scoped lang='scss'>
.madp-choose-member-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  .dialog-bg {
    width: 100%;
    height: 100%;
    opacity: 0.5;
    background: #000;
  }
  .com-dialog-container {
    position: absolute;
    width: 100%;
    padding: 60px 20px;
    border-radius: 5px;
    background: #fff;
    padding-bottom: 20px;
    bottom: -3px;
    .header {
      width: 100%;
      position: absolute;
      top: 16px;
      left: 0;
      .title {
        font-size: 15px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #2c2c2c;
        margin-left: 20px;
      }
      .el-icon-close {
        font-size: 16px;
        position: absolute;
        top: 0;
        right: 6px;
      }
    }
    .container {
      height: calc(100vh - 130px);
      .list {
        padding: 16px;
        padding-top: 10px;
        .empty {
          width: 100%;
          text-align: center;
          margin-top: 20px;
          font-size: 16px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(44, 44, 44, 0.8);
        }
      }
      .list-item {
        width: 100%;
        padding: 6px 6px;
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        border-bottom: 1px solid #e3e1e1;
        img {
          width: 40px;
          height: 40px;
          border-radius: 50%;
          margin-right: 10px;
        }
        .info {
          flex: 1;
          display: flex;
          margin-left: 8px;
          flex-direction: column;
          :nth-child(1) {
            font-size: 16px;
            font-family: PingFangSC-Medium;
            font-weight: 500;
            color: #2c2c2c;
          }
          :nth-child(2) {
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #58be6b;
          }
        }
        &:nth-child {
          border: none;
        }
      }
    }
  }
}
</style>